<?php

namespace app\admin\controller;

use app\admin\model\SysModel;

use app\BaseController;

use app\common\Constants\ErrorCode;

use think\Model;

use think\response\Json;



class Board extends ApiCommon

{



    /**

     * 用于判断权限

     * @permission 无限制

     * @allow 登录用户可访问

     * @author Mr.Li

     * @create 2021-05-26 16:20

     */

    public function initialize()

    {

        parent::initialize();

    }



    /**
     * 获取看板倒金字塔
     * @return Json
     * @author ran
     * @date 2021-09-22 17:09
     * mailbox 466180170@qq.com
     */

    public function getPyramidInfo():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->getPyramidInfo($shopIds,$request);

        $res = [
            'customer_count'=>$return['count']['customer_count'],
            'inshop_count'=>$return['count']['inshop_count'],
            'cj_count'=>$return['count']['cj_count'],
            'by_count'=>$return['count']['by_count'],
            'by_rate'=>$return['rate']['by_rate'],
            'cj_rate'=>$return['rate']['cj_rate'],
            'inshop_rate'=>$return['rate']['enter_rate'],
            'comprehensive_score' =>$return['level']
        ];

        return $this->success($res,'获取资源成功');
    }


    //进店数量
    public function enterShopCount():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->enterShop($shopIds,$request);
        $x =['线上进店','转介绍','门头外联'];
        $res = [
            'year'=>$return['year'],
            'one'=>$return['one'],
            'two'=>$return['two'],
            'x'=>$x
        ];
        return $this->success($res,'获取进店数量成功');
    }

    //指标1 -疤痕/痘痘/皮肤
    public function classEnterShop():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->classEnterShop($shopIds,$request);
        $x =['疤痕','痘痘','皮肤'];
        $res = [
            'year'=>$return['year'],
            'one'=>$return['one'],
            'two'=>$return['two'],
            'x'=>$x
        ];
        return $this->success($res,'获取进店率成功');
    }

    //成交及成交比例
    public function bargain():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->getPaySuccess($shopIds,$request);
        $x = ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'];
        $res = [
            'year'=>$return['year'],
            'cj_one'=>$return['cj_one'],
            'cj_two'=>$return['cj_two'],
            'cj_one_rate'=>$return['cj_one_rate'],
            'cj_two_rate'=>$return['cj_two_rate'],
            'x'=>$x
        ];
        return $this->success($res,'获取成交及成交比例');
    }
    //累计保有
    public function ShopRetainCustomers():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->ShopRetainCustomers($shopIds,$request);
        $x = ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'];
        $res = [
            'year'=>$return['year'],
            'lj_by_one'=>$return['lj_by_one'],
            'last_lj_by_one'=>$return['last_lj_by_one'],
            'x'=>$x
        ];
        return $this->success($res,'获取累计保有个数');
    }
    //周期性保有个数
    public function periodicityBaoyou():Json
    {

        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->periodicityBaoyou($shopIds,$request);
        $x = ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'];
        $res = [
            'year'=>$return['year'],
            'zqx_by_one'=>$return['zqx_by_one'],
            'last_zqx_by_one'=>$return['last_zqx_by_one'],
            'x'=>$x
        ];
        return $this->success($res,'获取周期性保有个数');
    }


    //获取Abcd分类客户数
    public function getAbcdCustomer():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $res  = $model->getCustomerValue($shopIds,$request);

        return $this->success($res,'获取abcd类顾客数及占比');
    }

    //年度客户消费金额
    public function yearConsumptionData():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return = $model->getYearCustomerPay($shopIds,$request);
        $title = ['人数'];
        $x = ['消费5w以上','消费1.5-5w','消费0.5-1.5w','消费0.5w以下'];
        $res = [
            'title'=>$title,
            'consumption'=>$return['consumption'],
            'x'=>$x
        ];
        return $this->success($res,'获取abcd类顾客数及占比');
    }


    //A客分析
    public function getACustomerAnalyse():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->ACustomerAnalyse($shopIds,$request);
        $title = ['人数'];
        $x = ['消费5w以上','消费3-5w','消费3w以下'];
        $res = [
            'title'=>$title,
            'consumption'=>$return['consumption'],
            'x'=>$x
        ];
        return $this->success($res,'获取A客分析成功');
    }

    //A类顾客保有率-周期性保有率- 累计保有率  -保有人数分析-周期性保有 - 累计保有  -周期性流失-累计流失
    public function getACustomerSynthesis():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return = $model->AcustomerRetainRate($shopIds,$request);
        $title1 = $title2 = $title3 = $title4 = $return['year'];
        $title = ['周期性保有率','累计保有率'];

        $x = ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'];
        $res = [
            'title'=>$title,
            'title1'=>$title1,
            'title2'=>$title2,
            'title3'=>$title3,
            'title4'=>$title4,
            'zqx_by_rate'=>$return['zqx_by_rate'],
            'lj_by_rate'=>$return['lj_by_rate'],
            'last_zqx_by'=>$return['last_zqx_by'],
            'zqx_by'=>$return['zqx_by'],
            'last_lj_by'=>$return['last_lj_by'],
            'lj_by'=>$return['lj_by'],
            'last_zqx_ls'=>$return['last_zqx_ls'],
            'zqx_ls'=>$return['zqx_ls'],
            'last_lj_ls'=>$return['last_lj_ls'],
            'lj_ls'=>$return['lj_ls'],
            'x'=>$x
        ];
        return $this->success($res,'获取A客分析成功');
    }

    //B客分析
    public function getBCustomerAnalyse():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->BCustomerAnalyse($shopIds,$request);
        $title = ['人数'];
        $x = ['消费3-5w','消费1.5-3w','消费1.5w以下'];
        $res = [
            'title'=>$title,
            'consumption'=>$return['consumption'],
            'x'=>$x
        ];
        return $this->success($res,'获取B客分析成功');
    }



    //B客保有率
    public function getBCustomerSynthesis():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return = $model->BcustomerRetainRate($shopIds,$request);

        $title = ['周期性保有率','累计保有率'];

        $title1 = $title2 = $title3 = $title4 = $return['year'];

        $x = ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'];
        $res = [
            'title'=>$title,
            'title1'=>$title1,
            'title2'=>$title2,
            'title3'=>$title3,
            'title4'=>$title4,
            'zqx_by_rate'=>$return['zqx_by_rate'],
            'lj_by_rate'=>$return['lj_by_rate'],
            'last_zqx_by'=>$return['last_zqx_by'],
            'last_lj_by'=>$return['last_lj_by'],
            'zqx_by'=>$return['zqx_by'],
            'lj_by'=>$return['lj_by'],
            'last_zqx_ls'=>$return['last_zqx_ls'],
            'last_lj_ls'=>$return['last_lj_ls'],
            'zqx_ls'=>$return['zqx_ls'],
            'lj_ls'=>$return['lj_ls'],
            'x'=>$x
        ];
        return $this->success($res,'获取B客分析成功');
    }


    //获取客户价值及门店评级
    public function customerValue():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $return  = $model->customerValue($shopIds,$request);

        $res = [
            'performance_total'=>$return['amount_sum'],
            'cj_count'=>$return['cj_count'],
            'customer_price'=>$return['amount_avg'],
            'shop_level' =>$return['shop_level'],

            'by_customer_num'=>$return['by_customer_num'],
            'abs_price'=>$return['abs_price'],
        ];
        return $this->success($res,'获取客户价值及门店评级成功');
    }



    //品项分析-品项业绩
    public function getItemAnalysis():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $res  = $model->ItemAnalysis($shopIds,$request);
        return $this->success($res,'获取品相分析品项业绩成功');
    }
    //品相分析-品相排序
    public function getItemData():Json
    {
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $res  = $model->getItemData($shopIds,$request);
        return $this->success($res,'获取品项排序成功');
    }

    //客户价值-年度消费金额
    public function getYearCustomerPay():Json{
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $model = new SysModel();
        $res  = $model->getYearCustomerPay($shopIds,$request);
        return $this->success($res,'获取年度消费金额成功');
    }

    //获取公共搜索门店市场数据
    public function getShopData():Json{
        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $model = new SysModel();
        $res  = $model->getShopData($shopIds,$request);
        return $this->success($res,'获取公共搜索门店市场数据成功');
    }

    /**
     * 员工价值板块 -第三个页面
     * @return Json
     * @author ran
     * @date 2021-09-22 17:09
     * mailbox 466180170@qq.com
     */

    public function getPersonInfo():Json
    {

        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $model = new SysModel();
        $res  = $model->getPersonInfo($shopIds,$request);

        return $this->success($res,'获取员工价值数据成功');
    }

    //员工明细-第三个页面
    public function getPersonData():Json{

        $request = $this->request->param();
        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $model = new SysModel();
        $return = $model->getPersonData($shopIds,$request);
        $res=[
            'list'=>$return['list'],
            'replenishment'=>$return['replenishment'],
            'hl'=>[
                'title'=>['日护理客数','护理量','护理总数'],
                'hll'=>$return['hll'],
                'hls'=>$return['hls'],
                'hlzs'=>$return['hlzs'],
                'performance'=>$return['performance'],
                'x'=>$return['personName'],
            ],
            'shop_id'=>$return['shop_id'],
            'market_id' =>$return['market_id'],
        ];
        return $this->success($res,'获取公共搜索门店市场数据成功');
    }




















}
